// pages/constellation/constellation.js

/// 转化农历到公历
var genreal = require("../../resources/file/calendar.js");
/// 查询星座
var convertInfo = require("../../resources/file/constellation.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShowInfo:false,
    arr: [['广', '州'], ["天", "下", "人"], ["地", "上", "神"]],
    value:'',
    customItem:"22",
    dateSection:'',
    lunarDate:'',
    solarDate:'',
    iconURL: '',
    costellationName: '',
    newArr: genreal.init(),
    initPickValue: [80, 0, 0],
    yearIndex: 80,
    monthIndex: 0,
    dayIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  ///  聚焦是触发
  _acuquireFocus: function(e) {
    console.log(e.target, e);
    this.setData({
      inputCanFocus:true
    });
  },

  /// 绑定列改变
  bindColumnChange:function(e) {
    if (e.detail.column == 0) {
      var arr = genreal.yearChange(e.detail.value);
      this.setData({
        yearIndex:e.detail.value,
        newArr:arr
      });
    }else if (e.detail.column == 1) {
      var arr = genreal.yearMonthChange(this.data.yearIndex, e.detail.value);
      this.setData({
        monthIndex: e.detail.value,
        newArr: arr
      });
    }else if (e.detail.column == 2) {
      this.setData({
        dayIndex: e.detail.value,
      });
    }
    // console.log(e.detail.column, e.detail.value);
  },

  /// 最后确认的数据
  bindChange: function(e) {
    // 阴历
    var str = genreal.dateStr(this.data.yearIndex, this.data.monthIndex, this.data.dayIndex);
    // 公历
    let date = genreal.lunar2Solar(this.data.yearIndex, this.data.monthIndex, this.data.dayIndex);
    // 星座信息
    let dic = convertInfo.constellationInfo(date);

    this.setData({
      isShowInfo:true,
      value: str,
      lunarDate: str,
      solarDate: genreal.dateStrFromDate(date),
      dateSection: dic.date,
      iconURL: dic.iconIndex,
      costellationName: dic.name
    });
    // console.log(e.detail.value);
  }
})